/*
 * Copyright (C) 2010 Moduad Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cc.telecomdigital.tdstock.activity.groups.more.push.client;

import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
 * Broadcast receiver that handles push notification messages from the server.
 * This should be registered as receiver in AndroidManifest.xml.
 * 
 * @author hunter
 */
public final class NotificationReceiver extends BroadcastReceiver
{

	private static final String	TAG	= NotificationReceiver.class
										.getSimpleName();

	// private NotificationService notificationService;

	public NotificationReceiver()
	{
	}

	// public NotificationReceiver(NotificationService notificationService) {
	// this.notificationService = notificationService;
	// }

	@Override
	public void onReceive(Context context, Intent intent)
	{
		TDStockLog.d(TAG, "NotificationReceiver.onReceive()...");
		String action = intent.getAction();
		TDStockLog.d(TAG, "action=" + action);
		if (Constants.ACTION_SHOW_NOTIFICATION.equals(action))
		{
			String notificationId = intent
					.getStringExtra(Constants.NOTIFICATION_ID);
			String notificationApiKey = intent
					.getStringExtra(Constants.NOTIFICATION_API_KEY);
			String notificationTitle = intent
					.getStringExtra(Constants.NOTIFICATION_TITLE);
			String notificationMessage_id = intent
					.getStringExtra(Constants.NOTIFICATION_MESSAGE_ID);
			String notificationStock_id = intent
					.getStringExtra(Constants.NOTIFICATION_MESSAGE_TYPE_ID);
			String notificationMessage = intent
					.getStringExtra(Constants.NOTIFICATION_MESSAGE);
			String notificationUri = intent
					.getStringExtra(Constants.NOTIFICATION_URI);

			TDStockLog.d(TAG, "notificationId=" + notificationId);
			TDStockLog.d(TAG, "notificationApiKey=" + notificationApiKey);
			TDStockLog.d(TAG, "notificationTitle=" + notificationTitle);
			TDStockLog.d(TAG, "notificationMessage=" + notificationMessage);
			TDStockLog.d(TAG, "notificationUri=" + notificationUri);
			TDStockLog.d(TAG, "notificationMessage_id="
					+ notificationMessage_id);
			TDStockLog
					.d(TAG, "notificationStock_id=" + notificationStock_id);
			Notifier notifier = new Notifier(context);
			notifier.notify(notificationId, notificationApiKey,
					notificationTitle, notificationMessage,
					notificationUri, notificationMessage_id,
					notificationStock_id);
		}

		// } else if (Constants.ACTION_NOTIFICATION_CLICKED.equals(action)) {
		// String notificationId = intent
		// .getStringExtra(Constants.NOTIFICATION_ID);
		// String notificationApiKey = intent
		// .getStringExtra(Constants.NOTIFICATION_API_KEY);
		// String notificationTitle = intent
		// .getStringExtra(Constants.NOTIFICATION_TITLE);
		// String notificationMessage = intent
		// .getStringExtra(Constants.NOTIFICATION_MESSAGE);
		// String notificationUri = intent
		// .getStringExtra(Constants.NOTIFICATION_URI);
		//
		// Log.e(LOGTAG, "notificationId=" + notificationId);
		// Log.e(LOGTAG, "notificationApiKey=" + notificationApiKey);
		// Log.e(LOGTAG, "notificationTitle=" + notificationTitle);
		// Log.e(LOGTAG, "notificationMessage=" + notificationMessage);
		// Log.e(LOGTAG, "notificationUri=" + notificationUri);
		//
		// Intent detailsIntent = new Intent();
		// detailsIntent.setClass(context, NotificationDetailsActivity.class);
		// detailsIntent.putExtras(intent.getExtras());
		// // detailsIntent.putExtra(Constants.NOTIFICATION_ID, notificationId);
		// // detailsIntent.putExtra(Constants.NOTIFICATION_API_KEY,
		// notificationApiKey);
		// // detailsIntent.putExtra(Constants.NOTIFICATION_TITLE,
		// notificationTitle);
		// // detailsIntent.putExtra(Constants.NOTIFICATION_MESSAGE,
		// notificationMessage);
		// // detailsIntent.putExtra(Constants.NOTIFICATION_URI,
		// notificationUri);
		// detailsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		// detailsIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
		//
		// try {
		// context.startActivity(detailsIntent);
		// } catch (ActivityNotFoundException e) {
		// Toast toast = Toast.makeText(context,
		// "No app found to handle this request",
		// Toast.LENGTH_LONG);
		// toast.show();
		// }
		//
		// } else if (Constants.ACTION_NOTIFICATION_CLEARED.equals(action)) {
		// //
		// }

	}

}
